//
//  RCUserVCMyCheckInCell.m
//  RocketProject
//
//  Created by chen jiedan on 13-8-25.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCUserVCMyCheckInCell.h"
#import "TTTAttributedLabel.h"
#import "CommonDefines.h"
#import "UIColor-Expanded.h"
#import "NSString+NSString_Ex_.h"
#import "UIImageView+Extented.h"



#define kMerchantNameColor 0xFF505050

@implementation RCUserVCMyCheckInCell{
    UILabel            *_shopName;
    UILabel            *_headLabel;
    UIView             *_scoreView;
    UILabel            *_priceLabel;
    TTTAttributedLabel *_descriptionLabel;
    UILabel            *_checkTime;
    BOOL               _needHeader;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier withHeader:(BOOL)needHeader
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        _needHeader = needHeader;
        [self createPlaceHolder:needHeader];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void) createPlaceHolder:(BOOL)needHeader
{
    CGFloat headerHeight = 0;
    if (needHeader) {
        headerHeight = kHeadHeight;
        [self needHeader];
    }
    
    _headLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 13+headerHeight, 200, 20)];
    _headLabel.backgroundColor = [UIColor clearColor];
    _headLabel.textColor = kNormalHeadTextColor;
    _headLabel.font = [UIFont fontWithName:kFontNameHelvetica size:20];
    [self.contentView addSubview:_headLabel];
    [_headLabel release];
    
    _scoreView = [[UIView alloc] initWithFrame:CGRectMake(15, 42+headerHeight, 80, 30)];
    [self.contentView addSubview:_scoreView];
    [_scoreView release];
    
    
    
    _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 42+headerHeight, 200, 15)];
    _priceLabel.backgroundColor = [UIColor clearColor];
    _priceLabel.font = [UIFont fontWithName:kFontNameHelvetica size:15];
    _priceLabel.textColor = kNormalTextColor;
    [self.contentView addSubview:_priceLabel];
    [_priceLabel release];
    
    
    _descriptionLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(15, 55+headerHeight, 250, 40)];
    _descriptionLabel.font = [UIFont fontWithName:kFontNameHelvetica size:15];
    _descriptionLabel.backgroundColor = [UIColor clearColor];
    _descriptionLabel.textColor = kNormalTextColor;
    _descriptionLabel.numberOfLines = 0;
    _descriptionLabel.leading = 6;
    [self.contentView addSubview:_descriptionLabel];
    [_descriptionLabel release];
    
    _checkTime = [[UILabel alloc] initWithFrame:CGRectMake(15, 95+headerHeight, 200, 15)];
    _checkTime.backgroundColor = [UIColor clearColor];
    _checkTime.font = [UIFont fontWithName:kFontNameHelvetica size:15];
    _checkTime.textColor = kNormalTextColor;
    [self.contentView addSubview:_checkTime];
    [_checkTime release];
    
    UIView *horizonLine = [[UIView alloc]initWithFrame:CGRectMake(15, 114+headerHeight, 320-30, 1)];
    horizonLine.backgroundColor = [UIColor colorWithHex:0xffe6e6e6];
    [self.contentView addSubview:horizonLine];
    [horizonLine release];
}


- (void) needHeader
{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, kHeadHeight)];
    headerView.backgroundColor = [UIColor colorWithRed:234.0/255 green:234.0/255 blue:234.0/255 alpha:1];
    _shopName = [[UILabel alloc] initWithFrame:CGRectMake(20, 5, 260, 15)];
    [headerView addSubview:_shopName];
    _shopName.backgroundColor = [UIColor clearColor];
    [_shopName setTextColor:kNormalHeadTextColor];
    _shopName.font = [UIFont fontWithName:kFontNameHelvetica size:15];
    [_shopName release];
    
    
    UIImageView *indicator = [[UIImageView alloc] initWithFrame:CGRectMake(295, 5, 20, 20)];
    [indicator autoResizeToSetImage:[UIImage imageNamed:@"icon_RCUserVC_indicate"]];
    [headerView addSubview:indicator];
    [indicator release];
    
    [self.contentView addSubview:headerView];
    [headerView release];
}

- (void) bindData:(RCDianpingItemDataModel *)itemData
{
    if (_needHeader) {
        _shopName.text = itemData.shopName;
        _headLabel.text = itemData.userName;
    }else{
        _headLabel.text = itemData.shopName;        
    }
    for (UIView *subView in _scoreView.subviews) {
        [subView removeFromSuperview];
    }
    
    int score = [itemData.score intValue];
    for (int i = 0; i < 5; i++) {
        UIImageView *t = [[UIImageView alloc] initWithFrame:CGRectMake(12*i, 0 ,10, 10)];
        if (score > i) {
            [t setImage:[UIImage imageNamed:@"start_highlight"]];
        }else{
            [t setImage:[UIImage imageNamed:@"start_normal"]];
        }
        [_scoreView addSubview:t];
        [t release];
    }
    if (![NSString stringIsNullOrEmpty:itemData.price]) {
        _priceLabel.hidden = NO;
        _priceLabel.text = [NSString stringWithFormat:@"人均：%@",itemData.price];
    }else{
        _priceLabel.hidden = YES;
    }
    _descriptionLabel.text = itemData.content;
    _checkTime.text = itemData.dateTime;
    
}

@end
